Test Setup Failed
Push — master ( a87e27...976b69 )
by Ankit
02:24
created

$(ꞌ#passRegisterꞌ).blur   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
var valName = 1;
2
var valEmail = 1;
3
var valUser = 1;
4
var valMob = 1;
5
var valPassRegister = 1;
6
var errorText = '{"font-size":"12px","color":"#a94442","display":"inline-block","padding": "5px","font-weight": "700"}';
7
errorText = JSON.parse(errorText);
8
var errorInput = '{"outline":"none","border-color":"#a94442"}';
9
errorInput = JSON.parse(errorInput);
10
var removeError = '{"outline":"none","border-color":"#ccc"}';
11
removeError = JSON.parse(removeError);
12
13
function initRegister()
14
{
15
    name();
16
    email();
17
    username();
18
    mob();
19
    passwordRegister();
20
}
21
22
// Name validation
23
24
$("#name").blur(function()
25
{
26
    name();
27
});
28
29
// Email validation
30
31
$("#email").keyup(function() {
32
    email();
33
});
34
35
$("#email").blur(function() {
36
    email();
37
});
38
39
40
// username validation
41
42
$("#username").blur(function() {
43
    username();
44
});
45
46
// Mobile validation
47
48
$("#mob").blur(function() {
49
    mob();
50
});
51
52
//Password validation
53
54
$("#passRegister").blur(function() {
55
    passwordRegister();
56
57
});
58
59
function registerCheck() {
60
    var name = $("#name").val();
61
    var email = $("#email").val();
62
    var username = $("#username").val();
63
    var mob = $("#mob").val();
64
    var password = $("#passRegister").val();
65
66
    initRegister();
67
68
    if(valName === 0 && valEmail === 0 && valUser === 0 && valMob === 0 && valPassRegister === 0)
69
    {
70
        var q = {"name":name,"email":email,"username":username,"mob":mob,"password":password};
71
        q = "q=" + JSON.stringify(q);
72
        // console.log(q);
73
        var xmlhttp = new XMLHttpRequest();
0 ignored issues
show
Bug introduced by
The variable XMLHttpRequest seems to be never declared. If this is a global, consider adding a /** global: XMLHttpRequest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
74
        xmlhttp.onreadystatechange = function()
75
        {
76
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
77
            {
78
                var result = JSON.parse(xmlhttp.responseText);
79
                // console.log(result);
80
                if(result['location'])
81
                {
82
                    location.href = result['location'];
83
                }
84
                if(result['name'])
85
                {
86
                    showNameError(result['name']);
87
                }
88
                if(result['password'])
89
                {
90
                    showPassErrorRegister(result['password']);
91
                }
92
                if(result['email'])
93
                {
94
                    showEmailError(result['email']);
95
                }
96
                if(result['username'])
97
                {
98
                    showUsernameError(result['username']);
99
                }
100
                if(result['mob'])
101
                {
102
                    showMobError(result['mob']);
103
                }
104
            }
105
        };
106
        xmlhttp.open("POST", "ajax/validate_register.php", true);
107
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
108
        xmlhttp.send(q);
109
    }
110
    else
111
    {
112
        // alert("Please Fill correct details");
113
        $("#myModal").modal()
114
    }
115
}
116
117
function showNameError(txt)
118
{
119
    $("input#name").prev("span").remove();
120
    $("#name").css(errorInput);
121
    var txt1 = $("<span></span>").text(txt).css(errorText);
122
    $("#name").before(txt1);
123
}
124
125
function showEmailError(txt)
126
{
127
    $("input#email").prev("span").remove();
128
    $("#email").css(errorInput);
129
    var txt1 = $("<span></span>").text(txt).css(errorText);
130
    $("#email").before(txt1);
131
}
132
function showUsernameError(txt)
133
{
134
    $("input#username").prev("span").remove();
135
    $("#username").css(errorInput);
136
    var txt1 = $("<span></span>").text(txt).css(errorText);
137
    $("#username").before(txt1);
138
}
139
140
function showMobError(txt)
141
{
142
    $("input#mob").prev("span").remove();
143
    $("#mob").css(errorInput);
144
    var txt1 = $("<span></span>").text(txt).css(errorText);
145
    $("#mob").before(txt1);
146
}
147
148
function showPassErrorRegister(txt)
149
{
150
    $("input#passRegister").prev("span").remove();
151
    $("#passRegister").css(errorInput);
152
    var txt1 = $("<span></span>").text(txt).css(errorText);
153
    $("#passRegister").before(txt1);
154
}
155
156
function name()
157
{
158
    var name = $("#name").val();
159
    $("#name + span").text("");
160
    if(name === "")
161
    {
162
        valName = 1;
163
        showNameError(" *Please input your name");
164
    }
165
    else
166
    {
167
        $("#name").css(removeError);
168
        valName = 0;
169
    }
170
}
171
172
function email()
173
{
174
    var val = $("#email").val();
175
    var ret = validate_email(val);
176
    $("input#email").prev("span").remove();
177
    if(val === "")
178
    {
179
        valEmail = 1;
180
        showEmailError(" *Enter Your email address");
181
    }
182
    else if(!ret)
183
    {
184
        valEmail = 1;
185
        showEmailError(" *Invalid Email");
186
    }
187
    else
188
    {
189
        $("#email").css(removeError);
190
        valEmail = 0;
191
    }
192
}
193
194
function username()
195
{
196
    var val = $("#username").val();
197
    var re = /^\S+@/;
198
199
    $("input#username").prev("span").remove();
200
    if(val === "")
201
    {
202
        valUser = 1;
203
        showUsernameError(" *Enter Your username");
204
    }
205
    else if(re.test(val))
206
    {
207
        valUser = 1;
208
        showUsernameError(" *Invalid username");
209
    }
210
    else
211
    {
212
        $("#username").css(removeError);
213
        valUser = 0;
214
    }
215
}
216
217
function mob()
218
{
219
    var mob = $("#mob").val();
220
    var re = /^[0-9]{10}$/;
221
    $("input#mob").prev("span").remove();
222
    if(mob === "")
223
    {
224
        valMob = 1;
225
        showMobError(" *Enter your mobile no.");
226
    }
227
    else if(!re.test(mob))
228
    {
229
        valMob = 1;
230
        showMobError(" *Enter 10 digit mobile no.");
231
    }
232
    else
233
    {
234
        $("#mob").css(removeError);
235
        valMob = 0;
236
    }
237
}
238
239
function passwordRegister()
240
{
241
    var pass = $("#passRegister").val();
242
    $("input#passRegister").prev("span").remove();
243
    if(pass === "")
244
    {
245
        valPassRegister = 1;
246
        showPassErrorRegister(" *Enter your password");
247
    }
248
    else
249
    {
250
        $("#passRegister").css(removeError);
251
        valPassRegister = 0;
252
    }
253
}
254
255
function validate_email(val)
256
{
257
    var re = /^\S+@\w+\.\w+$/;
258
    return re.test(val);
259
}